﻿

using System;

namespace ZDK.Infra.Helpers
{
    //字符串转换
    public static class StrHelper
    {
        #region StrToHexByte
        /// <summary>
        /// 字符串转16进制字节数组，2个字符算一个16进制字节
        /// </summary>
        /// <param name="hexString">02 F1 1B... </param>
        /// <returns></returns>
        public static byte[] StrToHexByte(string hexString)
        {
            hexString = hexString.Replace("0x", "");
            hexString = hexString.Replace("\r\n", "");
            hexString = hexString.Replace(" ", "");
            hexString = hexString.Replace("-", "");
            byte[] returnBytes = new byte[hexString.Length / 2];
            for (int i = 0; i < returnBytes.Length; i++)
                returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
            return returnBytes;
        }
        #endregion
    }
}
